]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
misc: Toggle IBus OSK capability on OSK visibility
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 9 Aug 2022 14:00:33 +0000 (16:00 +0200)
committerMarge Bot <marge-bot@gnome.org>
Wed, 10 Aug 2022 10:14:40 +0000 (10:14 +0000)
Newer versions of IBus (> 1.5.26) have the IBUS_CAP_OSK capability
which can be used to hint the active IM about an OSK driving input as
opposed to a physical keyboard. This may be used by IMs to tweak their
behavior to suit OSKs better.

Add the GNOME Shell side handling for this capability, and toggle it
on whenever the OSK is visible.

Since this is a far too new enum value and we don't want such new
IBus dependency, this change plays fast and loose with JS guarantees,
since a logical OR with an undefined value results in the other operand
unmodified it will work for older versions where the capability does not
exist and thus we want nothing extra enabled.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2415>

js/misc/inputMethod.js
js/ui/keyboard.js

index 856bf57aecd855689878a7eaa99d93d64ec63628..fba2730bd1a483bb6927a4cafb2d352c0360ee23 100644 (file)
@@ -3,6 +3,7 @@
 const { Clutter, GLib, Gio, GObject, IBus } = imports.gi;
 
 const Keyboard = imports.ui.status.keyboard;
+const Main = imports.ui.main;
 
 Gio._promisify(IBus.Bus.prototype,
     'create_input_context_async', 'create_input_context_async_finish');
@@ -42,6 +43,9 @@ class InputMethod extends Clutter.InputMethod {
     _updateCapabilities() {
         let caps = IBus.Capabilite.PREEDIT_TEXT | IBus.Capabilite.FOCUS | IBus.Capabilite.SURROUNDING_TEXT;
 
+        if (Main.keyboard.visible)
+            caps |= IBus.Capabilite.OSK;
+
         if (this._context)
             this._context.set_capabilities(caps);
     }
@@ -72,10 +76,14 @@ class InputMethod extends Clutter.InputMethod {
         this._context.connect('forward-key-event', this._onForwardKeyEvent.bind(this));
         this._context.connect('destroy', this._clear.bind(this));
 
+        Main.keyboard.connectObject('visibility-changed', () => this._updateCapabilities());
+
         this._updateCapabilities();
     }
 
     _clear() {
+        Main.keyboard.disconnectObject(this);
+
         if (this._cancellable) {
             this._cancellable.cancel();
             this._cancellable = null;
index ac36f3573a5961dec642c6b666bbccee680b1e4c..77a6f7d5cc64449a4f9f13b3ec90ab8eb3801bc7 100644 (file)
@@ -1180,8 +1180,10 @@ var Keypad = GObject.registerClass({
     }
 });
 
-var KeyboardManager = class KeyBoardManager {
+var KeyboardManager = class extends Signals.EventEmitter {
     constructor() {
+        super();
+
         this._keyboard = null;
         this._a11yApplicationsSettings = new Gio.Settings({ schema_id: A11Y_APPLICATIONS_SCHEMA });
         this._a11yApplicationsSettings.connect('changed', this._syncEnabled.bind(this));
@@ -1237,6 +1239,7 @@ var KeyboardManager = class KeyBoardManager {
         if (enabled && !this._keyboard) {
             this._keyboard = new Keyboard();
             this._keyboard.connect('visibility-changed', () => {
+                this.emit('visibility-changed');
                 this._bottomDragAction.enabled = !this._keyboard.visible;
             });
         } else if (!enabled && this._keyboard) {